package vj.string;

public class StringPermutation {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String s = "abcd";
		char a[] = s.toCharArray();
		allPrem(a, 0, a.length - 1);
		
	}
	
	public static void allPrem(char a[], int l, int u) {
		if(l == u) {
			for(int i = 0; i <= u; i++)
				System.out.print(a[i]);
			System.out.println();
		} else {
			for(int i = l; i <= u; i++) {
				swap(a, i, l);
				allPrem(a, l+1, u);
				swap(a, i, l);
			}
		}
	}

	private static void swap(char[] a, int i, int l) {
		char tmp = a[l];
		a[l] = a[i];
		a[i] = tmp;
		
	}

}
